package com.aaa.controller.mht;

import com.aaa.aspect.LogMonitor;
import com.aaa.controller.BaseController;
import com.aaa.entity.PageSortEntity;
import com.aaa.entity.Result;
import com.aaa.entity.fpa.ViewTestResultFpa;
import com.aaa.entity.mht.TestPlanMht;
import com.aaa.entity.mht.TestResultMht;
import com.aaa.entity.mht.ViewTestResultMht;
import com.aaa.service.mht.TestResultMhtService;
import com.aaa.service.mht.ViewTestResultMhtService;
import com.github.pagehelper.Page;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.lang.annotation.Retention;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * (ViewTestResultMht)表控制层
 *
 * @author makejava
 * @since 2022-09-05 19:41:05
 */
@RestController
@RequestMapping("viewTestResultMht")
public class ViewTestResultMhtController extends BaseController {
    /**
     * 服务对象
     */
    @Resource
    private ViewTestResultMhtService viewTestResultMhtService;

    @Resource
    private TestResultMhtService testResultMhtService;


    //查询所有
    @RequestMapping(method = RequestMethod.GET, value = "/queryAll.do")
    public Result queryAll(PageSortEntity pageSortEntity, ViewTestResultMht viewTestResultMht) {
        Page page = viewTestResultMhtService.queryAll(pageSortEntity, viewTestResultMht);
        return success(page.getResult(), page.getTotal());
    }

    //查询单个返回测试结果
    @RequestMapping(method = RequestMethod.POST, value = "queryAllById.do")
    public Result queryResultById(ViewTestResultMht viewTestResultMht) {
        List<ViewTestResultMht> viewTestResultMhts = viewTestResultMhtService.queryAllById(viewTestResultMht);
        ViewTestResultMht viewTestResultMht1 = viewTestResultMhts.get(0);
        return success(viewTestResultMht1);
    }

    //查询单个返回测试结果
    @RequestMapping(method = RequestMethod.POST, value = "queryResultToReport.do")
    public Result queryResultToReport() {
        Map map = viewTestResultMhtService.queryResultToReport();
        return success(map);
    }


    //查询返回单个结果以给前端页面展示
    @RequestMapping(method = RequestMethod.POST, value = "ViewQueryById.do")
    public Result ViewQueryById() {
        Map map = viewTestResultMhtService.queryResultToReportbyid();
        return success(map);
    }

    //删除单条数据，去测试者表中删除
    @RequestMapping(method = RequestMethod.POST, value = "delete.do")
    @ResponseBody
    public Result delete(String[] ids) {
        List list = new ArrayList();
        for (String id : ids) {
            list.add(id);
        }
        testResultMhtService.deleteById(list);
        return success("删除成功");
    }

    //查询测试结果到查看详情
    @RequestMapping(method = RequestMethod.GET, value = "queryTestResultById.do")
    public Result queryTestResultById(PageSortEntity pageSortEntity,TestResultMht testResultMht){
        Page page = viewTestResultMhtService.queryTestResultById(pageSortEntity, testResultMht);
        return success(page.getResult(),page.getTotal());
    }


}

